package com.moco.launcher.activity;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;

import com.moco.launcher.LauncherApplication;
import com.moco.launcher.R;
import com.moco.launcher.adapter.MainFlagmentAdapter;
import com.moco.launcher.fragment.SleepWaitFragment;
import com.moco.launcher.listener.FragmentListener;
import com.oazon.common.Logger;

public class SleepWaitActivity extends BaseFragmentActivity implements
		FragmentListener {
	private static final String TAG = "SceneActivity";

	private ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
	private MainFlagmentAdapter mFlagmentAdapter = null;
	private ViewPager mViewPager = null;
	private LauncherApplication mApp = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		this.setContentView(R.layout.main_layout);

		initViewPager();
		initFragment();

		mApp = ((LauncherApplication)getApplication());
		mApp.registerActivty(this);
	}

	private void initViewPager() {
		mFlagmentAdapter = new MainFlagmentAdapter(this,getSupportFragmentManager());
		mViewPager = (ViewPager)this.findViewById(R.id.main_pager);
		mViewPager.setOffscreenPageLimit(1);
		mViewPager.setAdapter(mFlagmentAdapter);
	}

	/**
	 * 初始化Fragment
	 */
	private void initFragment() {
		mFragments.clear();
		
		SleepWaitFragment tempFragment = new SleepWaitFragment();
		tempFragment.registerCallback(this);
		mFragments.add(tempFragment);
		mFlagmentAdapter.appendList(mFragments);
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		Logger.d(TAG, "the launcher receive dispatchTouchEvent event");
		mApp.resetStartTime();
		return super.dispatchTouchEvent(event);
	}

	@Override
	public void finishActivity() {
		this.finish();
	}
}
